//core.manage.js

//Page admin overlay
jQuery('.silk-core-control-overlay').entwine({

    'onmatch': function(){
	jQuery(this).fadeOut();
    },

    'fadeOut': function(){
	jQuery(this).css('opacity', '0.5');
	jQuery(this).css('-moz-opacity', '0.5');
	jQuery(this).css('filter', 'alpha(0.5)');
    },

    'fadeIn': function(){
	jQuery(this).css('opacity', '1.0');
	jQuery(this).css('-moz-opacity', '1.0');
	jQuery(this).css('filter', 'alpha(1.0)');
    },

    'onmouseover': function(){
	    jQuery(this).fadeIn();
    },

    'onmouseout': function(){
	    jQuery(this).fadeOut();
    }

});


jQuery('body').entwine({

    'initPageControls': function(){
	var page_slug = jQuery(this).attr('id');
	var pageControls = ' \
	<div id="silk-core-page-controls" class="silk-core-control-overlay"> \
	    <ul> \
		<li><a class="silk-core-edit-page" href="/' + page_slug + '?action=edit">Edit Page</a></li> \
		<li><a class="silk-core-create-page" href="/create-object?type=page&parent=' + page_slug + '">Add Child Page</a></li> \
		<li><a class="silk-core-edit-page-permissions" href="javascript:void(0)">Page Permissions</a></li> \
	    </ul> \
	</div>';

	jQuery(this).append(pageControls);

	jQuery('a.silk-core-edit-page-permissions').click(function(){
	    jQuery('body').openLightbox('/' + page_slug + '?action=permissions&lb=1', 750, 325);
	});
    },

    'openLightbox': function(pUrl, pWidth, pHeight){
	var lb = jQuery('<div id="silk-core-lightbox"></div>');

	lb.html('<iframe style="width:750px;height:350px;border:none;margin:0;padding:0;top:0;left:0;" src="' + pUrl + '"></iframe>')

	lb.dialog({
	    autoOpen: true,
	    modal: true,
	    width: pWidth,
	    height: pHeight,
	    title: 'Page Template Permissions'
	});
    },

    'closeLightbox': function(){

	jQuery('div#silk-core-lightbox').dialog('close');
    }
});


jQuery(document).ready(function(){
    jQuery('body').initPageControls();
});